import urllib3
import json
from 天气 import select
def ip_located(ip):
    """
    根据IP定位
    :param ip:
    :return:
    """
    url = 'http://api.map.baidu.com/location/ip?ak=6DsLdmd0pPBBS7AFYeq5mDBnb2Xx5DNI&ip=' + ip + '&coor=bd09ll'
    http = urllib3.PoolManager()
    r = http.request("GET", url)
    msg_json = json.loads(r.data.decode())
    # print(msg_json.items())
    # print()
    num_o=0
    for item in msg_json.items():
        num_o+=1
        if num_o==2:
            # print(item[1]['address_detail']["city"]) #江苏省南京市
            return item[1]['address_detail']["city"]


select(ip_located("112.2.255.139"))